﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Sizebox.CharacterEditor
{
	// Token: 0x02000240 RID: 576
	public class BodySliderView : BaseView
	{
		// Token: 0x06000C4E RID: 3150 RVA: 0x000645E8 File Offset: 0x000627E8
		protected override void Awake()
		{
			base.Awake();
			this.nextSetButton.onClick.AddListener(delegate()
			{
				this.ChangeSliderSet(1);
			});
			this.prevSetButton.onClick.AddListener(delegate()
			{
				this.ChangeSliderSet(-1);
			});
			this.CreateSliders();
		}

		// Token: 0x06000C4F RID: 3151 RVA: 0x00064639 File Offset: 0x00062839
		protected override void OnEnable()
		{
			base.OnEnable();
			this.PrepareSliders();
		}

		// Token: 0x06000C50 RID: 3152 RVA: 0x00064648 File Offset: 0x00062848
		private void PrepareSliders()
		{
			if (!this.handleManager.TargetEditor)
			{
				return;
			}
			SkeletonEdit component = this.handleManager.TargetEditor.GetComponent<SkeletonEdit>();
			if (!component)
			{
				return;
			}
			foreach (SkeletonEditSlider skeletonEditSlider in this.sliders)
			{
				skeletonEditSlider.RegisterSkeleton(component);
			}
			foreach (SkeletonEditSliderSetUI skeletonEditSliderSetUI in this.sliderSets)
			{
				skeletonEditSliderSetUI.gameObject.SetActive(false);
			}
			this.ChangeSliderSet(0);
		}

		// Token: 0x06000C51 RID: 3153 RVA: 0x00064730 File Offset: 0x00062930
		private void CreateSliders()
		{
			this.sliders = new List<SkeletonEditSlider>();
			foreach (SkeletonEditSliderSet skeletonEditSliderSet in this.sliderSetsObject.Sets)
			{
				SkeletonEditSliderSetUI skeletonEditSliderSetUI = UnityEngine.Object.Instantiate<SkeletonEditSliderSetUI>(this.sliderSetUiPrefab, this.sliderSetsParent);
				skeletonEditSliderSetUI.Set = skeletonEditSliderSet;
				this.sliderSets.Add(skeletonEditSliderSetUI);
				foreach (SkeletonEditSliderObject skeletonEditSliderObject in skeletonEditSliderSet.sliders)
				{
					if (skeletonEditSliderObject)
					{
						SkeletonEditSliderUI skeletonEditSliderUI = UnityEngine.Object.Instantiate<SkeletonEditSliderUI>(this.sliderUiPrefab, skeletonEditSliderSetUI.ContentTransform);
						SkeletonEditSlider item = skeletonEditSliderUI.Initialize(this.bodyView.DataId, skeletonEditSliderObject);
						this.sliders.Add(item);
					}
				}
			}
			if (this.sliderSets.Count <= 0)
			{
				return;
			}
			foreach (SkeletonEditSliderSetUI skeletonEditSliderSetUI2 in this.sliderSets)
			{
				skeletonEditSliderSetUI2.gameObject.SetActive(false);
			}
		}

		// Token: 0x06000C52 RID: 3154 RVA: 0x000648AC File Offset: 0x00062AAC
		private void ChangeSliderSet(int indexChange)
		{
			this.sliderSets[this.index].gameObject.SetActive(false);
			this.index += indexChange;
			if (this.index < 0)
			{
				this.index = this.sliderSets.Count - 1;
			}
			else if (this.index >= this.sliderSets.Count)
			{
				this.index = 0;
			}
			this.sliderSets[this.index].gameObject.SetActive(true);
			this.setNameText.text = this.sliderSets[this.index].Set.name;
		}

		// Token: 0x04001178 RID: 4472
		[Space(15f)]
		[SerializeField]
		private HandleManager handleManager;

		// Token: 0x04001179 RID: 4473
		[SerializeField]
		private BodyView bodyView;

		// Token: 0x0400117A RID: 4474
		[SerializeField]
		private RectTransform sliderSetsParent;

		// Token: 0x0400117B RID: 4475
		[SerializeField]
		[Header("Prefabs")]
		private SkeletonEditSliderSetObject sliderSetsObject;

		// Token: 0x0400117C RID: 4476
		[SerializeField]
		private SkeletonEditSliderSetUI sliderSetUiPrefab;

		// Token: 0x0400117D RID: 4477
		[SerializeField]
		private SkeletonEditSliderUI sliderUiPrefab;

		// Token: 0x0400117E RID: 4478
		[Header("Buttons")]
		[SerializeField]
		private Button nextSetButton;

		// Token: 0x0400117F RID: 4479
		[SerializeField]
		private Button prevSetButton;

		// Token: 0x04001180 RID: 4480
		[SerializeField]
		[Header("Set Name Text")]
		private Text setNameText;

		// Token: 0x04001181 RID: 4481
		private List<SkeletonEditSliderSetUI> sliderSets = new List<SkeletonEditSliderSetUI>();

		// Token: 0x04001182 RID: 4482
		private List<SkeletonEditSlider> sliders = new List<SkeletonEditSlider>();

		// Token: 0x04001183 RID: 4483
		private int index;
	}
}
